CPE 332
Computer Engineering
Mathematics II
Chapter 1 Vector
– Download Material, Course Notes
– Download Slides
– Download HW Solutions
– Grading
– Announcements
– Resources
• Period 1
– Course Outlines
– Course Web Site
– Part I Chapter 1 Vector (Review)
– Breaks
– Part I Chapter 1 Vector (Review)
• Assignment:
– ยังไม่มีการบ ้าน
– Download MATLAB Tutorial 1-5 และลองทํา Exercise ดู
• Next Week ต่อ Vector และ Chapter 2 เรื่อง Matrix
CPE 332 T1-57 Wk1
Definition of Vector
Definition of Vector
• เนื่องจาก Vector มีทั้งขนาดและทิศทาง เรา
สามารถเขียน Vector เป็นสองส่วน
– ส่วนขนาดแทนที่ด ้วย Scalar
– ส่วนทิศทาง จะแทนที่ด ้วย Unit Vector ที่มีทิศทาง
เดียวกับ Vector เดิม
ˆ
ˆ
F = F = F f = F f = F i + F j + F k = F (cosαi + cos βj + cos k γ )
1
2
3
• การกําหนดทิศทาง อาจจะกําหนดเป็น Component ในแกน
Coordinate (x,y,z); อาจจะกําหนดเป็นมุมที่กระทํากับแกน
Coordinate
• อาจจะกําหนดเป็น Ratio ที่กระทํากับแกนก็ได ้
• จะกล่าวต่อไปภายหลัง
– เราจะเน ้นที่สองอันแรก คือกําหนดเป็น Component i,j,k ในแกน
x,y,z
– หรือกําหนดในรูป Cosine ของมุม
– ทั้งสองอันนี้จะเกี่ยวข ้องกับ Unit Vector
• เนื่องจาก Vector ประกอบด ้วยทั้งขนาดและ
ทิศทาง
– พีชคณิต เช่น บวก ลบ คูณ หาร จะไม่เหมือนกับ Scalar เนื่องจากต ้องนําทิศทางมาประกอบการคํานวณด ้วย
– การ บวก-ลบ ของ Vector จะได ้ Vector ใหม่ที่ขนาด
และทิศทางต่างจากเดิม
– การคูณ เราจะไม่ใช ้คําว่า ‘Multiplication’ แต่จะใช ้คําว่า
‘Product’ แบ่งเป็นสองประเภท
• Scalar Product (Dot Product; ●) จะได ้ Scalar
• Vector Product (Cross Product; X) จะได ้ Vector ที่ตั้งฉาก
กับ Vector เดิมทั้งสอง
Addition and Substraction
การประยุกต์ใช ้ใน Plane
Geometry
Component Vector
Component Vector in
Cartesian Coordinate
Component Vector in
Cartesian Coordinate
Component Vector in
Cartesian Coordinate
Position Vector
• จุดใน Space สามารถแสดงได ้โดยใช ้ Vector
เริ่มจาก Origin
– อาจเรียก Location Vector หรือ Radius Vector
– จุด P แสดงได ้โดยใช ้ Vector OP
– และสามารถแสดงได ้โดยใช ้ Component Vector
Position Vector และ
Addition-Subtraction using
Component Vector
• การเขียน Vector ในลักษณะ Component
จะสามารถบวกและลบกันได ้ง่าย โดยการ
บวกลบแต่ละ Component บนแกนเดียวกัน
– Vector Product สามารถคํานวณได ้เช่นกัน
• จุดใน Space สามารถแทนด ้วย Vector เริ่ม
จากจุด Origin เรียก Position Vector
– Vector ที่เกิดจากสองจุดใน Space สามารถ
คํานวณได ้จาก Position Vector นี้
r
Any vectors in Cartesian
Coordinates
• Given 2 Points, P(x1,y1,z1) and
Q(x2,y2,z2)
– We have OP+PQ=OQ
– Then PQ = OQ – OP
• PQ = x2i+y2j+z2k – x1i+y1j+z1k
• PQ =(x2-x1)i+(y2-y1)j+(z2-z1)k
Z
Q(x2,y2,z2)
O
Y
P(x1,y1,z1)
X
Any vectors in Cartesian
Coordinates
• Given 2 Points, P(x1,y1,z1) and
Q(x2,y2,z2)
– PQ =(x2-x1)i+(y2-y1)j+(z2-z1)k
– Also magnitude or length of vector is the
distance between those 2 points (Euclidian
Distance)
• PQ = √(x2-x1)2+(y2-y1)2+(z2-z1)2
Z
Q(x2,y2,z2)
O
Y
P(x1,y1,z1)
X
• Vector สามารถเขียนเป็นสองส่วนประกอบ
=
A
A aˆ
– ขนาด สามารถหาได ้ง่าย กรณี Position Vector
– ทิศทาง คือ Unit Vector ที่มีทิศทางเดียวกันกับ
Vector นั้น
• ทิศทาง สามารถแตกเป็น Component Vector บนแต่ละ
แกนได ้ด ้วย
• ทิศทางสามารถกําหนดด ้วยมุมที่ทํากับแต่ละแกนได ้ด ้วย
• ทั้งสองแบบนี้ สัมพันธ์กันทางตรีโกณมิติ โดยการกําหนด
ด ้วยค่า Cosine ของมุม เรียก Direction Cosine
Direction Cosine
• Position vector OP
– Magnitude equal to OP = √x2+y2+z2
– Direction: cosαi+cosβj+cosγk
• Called Direction Cosine
We have
F3
cosα =F1/OP
cosβ =F2/OP
F2
cosγ =F3/OP
F1
Direction Cosine and
Direction Ratio
Direction Cosine and
Direction Ratio
• Given points P1(2,-4,5) and P2(1,3,-2),
find the vector P1P2 and its magnitude
and direction
– OP1 = 2i-4j+5k and OP2 = i+3j-2k
– P1P2=OP2-OP1=-i+7j-7k
– P1P2 = √1+49+49=√99
– Cos α = -1/√99 then α = 95.8 degree
– Cos β = 7/√99 then β = 45.3 degree
– Cos γ = -7/√99 then γ = 134.7 degree
Direction Cosine and
Direction Ratio
• Vector Product
– Scalar Product(Dot)
– Vector Product(Cross)
• Chapter II: MATRICES
• HW II
CPE 332
Computer Engineering
Mathematics II
Week 2
Chapter 1 Vector (cont.)
Chapter 2 Matrix
• Chapter 1 Cont.
• Break
• Chapter 2: Matrix
• Download Homework 1: Chapter 1
– Due Next Week
Component Vector
Component Vector in
Cartesian Coordinate
Component Vector in
Cartesian Coordinate
Position Vector
• จุดใน Space สามารถแสดงได ้โดยใช ้ Vector
เริ่มจาก Origin
– อาจเรียก Location Vector หรือ Radius Vector
– จุด P แสดงได ้โดยใช ้ Vector OP
– และสามารถแสดงได ้โดยใช ้ Component Vector
Position Vector และ
Addition-Subtraction using
Component Vector
Any vectors in Cartesian
Coordinates
• Given 2 Points, P(x1,y1,z1) and
Q(x2,y2,z2)
– PQ =(x2-x1)i+(y2-y1)j+(z2-z1)k
– Also magnitude or length of vector is the
distance between those 2 points (Euclidian
Distance)
• PQ = √(x2-x1)2+(y2-y1)2+(z2-z1)2
Z
Q(x2,y2,z2)
O
Y
P(x1,y1,z1)
X
• Vector สามารถเขียนเป็นสองส่วนประกอบ
=
A
A aˆ
– ขนาด สามารถหาได ้ง่าย กรณี Position Vector
– ทิศทาง คือ Unit Vector ที่มีทิศทางเดียวกันกับ
Vector นั้น
• ทิศทาง สามารถแตกเป็น Component Vector บนแต่ละ
แกนได ้ด ้วย
• ทิศทางสามารถกําหนดด ้วยมุมที่ทํากับแต่ละแกนได ้ด ้วย
• ทั้งสองแบบนี้ สัมพันธ์กันทางตรีโกณมิติ โดยการกําหนด
ด ้วยค่า Cosine ของมุม เรียก Direction Cosine
Direction Cosine
• Position vector OP
– Magnitude equal to OP = √x2+y2+z2
– Direction: cosαi+cosβj+cosγk
• Called Direction Cosine
We have
F3
cosα =F1/OP
cosβ =F2/OP
F2
cosγ =F3/OP
F1
• Vector Product
– Scalar Product(DOT)
– Vector Product(Cross)
Scalar Product(DOT)
Scalar Product (DOT)
A
θ
n
A●n=Acosθ
Scalar(Dot) Product
– A●(B+C)=A●B+A●C
– Let A = a1i+a2j+a3k, B = b1i+b2j+b3k
• We have A●B = a1b1+a2b2+a3b3
– Also
– Given S=ai+bj, the equation of line perpendicular to this vector is in the form
• ax+by=c
Line ax+by=c
S=ai+bj
DOT Product
• Find the angle between the vector
– A=i-j-k and B = 2i+j+2k
• We calculate A●B = 1.2-1.1-1.2=-1
• Also A = √(1+1+1)=√3
• Also B = √(4+1+4)=3
• Then Cos θ = -1/3√3
– θ = 101.1 degrees
Vector Product (Cross)
Cross Product
3 Vector Products
• Let A=2i+3j-k, B=i+j+2k
– A●B = 2+3-2 = 3
– A×B = (6+1)i-(4+1)j+(2-3)k=7i-5j-k
– A×B is orthogonal to both A and B
• Test : A●(A×B) = (2i+3j-k)●(7i-5j-k) = 14-15+1=0
• Test : B●(A×B) = (i+j+2k)●(7i-5j-k) = 7-5-2=0
• ใน 2D สมการเส ้นตรงจะมี general Form
– Ax+By=C
• ใน 3D สมการของ Plane จะมี General
Form
– Ax+By+Cz=D
– D เป็นค่าคงที่ ทุกๆสมการในรูปเดียวกัน แต่ค่า
D ต่างกัน จะเป็นระนาบที่ขนานกัน
• 3x-2y+5z = 3 จะขนานกับ 3x-2y+5z = 6
• กําหนดสมการของ Plane 2x+3y+2z=5 จง
หา unit vector ที่ตั้งฉากกับ Plane นี้
– กําหนด 3 จุด คือ A, B, C ดังนี้
– A: x=0,y=0,ดังนั้น z=5/2 A(0,0,2.5)
– B: x=1,y=0, ดังนั้น z=(5-2)/2 B(1,0,1.5)
– C: x=0,y=1, ดังนั้น z=(5-3)/2 C(0,1,1)
– Vector AB x AC จะได ้ Vector ที่ตั้งฉากกับ
Plane
AB = i − k,
AC = j − 1. k
5
i
j
k
AB × AC = 1
0
−1 = i +1.5j + k
0
1
−1.5
1
uˆ =
[i +1 5. j+ k]
.
4 25
• สังเกตุว่าทุกๆ Vector ที่เป็น multiple ของ
2i+3j+2k จะตั้งฉากกับ Plane 2x+3y+2z=k
เสมอ โดยที่ k เป็นค่าคงที่ใดๆ
• จงหาสมการของ Plane ที่ตั้งฉากกับ Vector
3i-2j-k และกําหนดให ้จุด (1,1,2) อยู่บน
Plane นั้น
– จากตัวอย่างก่อน เราได ้สมการของ Plane เป็น
3x-2y-z= k
– เราหาค่า k โดยแทนค่าจุด (1,1,2) ลงใน
สมการดังนี้ 3(1)-2(1)-(2)=-1=k
– ดังนั้นสมการที่ต ้องการจะเป็น 3x-2y-z+1=0
Definition of Matrix
Row Matrix, Column Matrix
Basic Operations
Matrix Multiplication
Square Matrix
Matrix Transpose
Types of Matrix
Types of Matrix
Types of Matrix
Types of Matrix
Types of Matrix
Matrix Inverse
Orthogonal/Unitary Matrix
Orthogonal Vector
Orthogonal Vector
1
3
5
A = 3
2
6
a
is
s
quare ma
trix of
orde
3
r ×
3, A
al
is
so a
s
ymmetric ma
trix
5
6
4
0
− 3
5
B =
3
0
− 6
a
is
s
quare ma
trix of
orde
3
r ×
3, B
al
is
so a
sk
ew - symmetric ma
trix
− 5 6
0
1
0
0
C = 0
2
0
a
is
di
agonal ma
trix, Di
ag( )
C = {1,
3
2,
t
}, race( )
C = 1 + 2 + 3 = 6
0 0 3
C
al
is
so a
s
ymmetric ma
trix.
2 3 3
D = 0
−1 4
an
is
uppe
di
r agonal ma
trix
0 0 1
2 0 0
E = 1
0
0
a
is
l
ower di
agonal ma
trix
3 0 1
1 0 0
1 0
I =
,
I =
2
3
0 1 0
0 1
0 0 1
F
a
or
ma
ny
trix A
ha
we
ve AAT
a
is
s
ymmetric ma
trix
, ATA
al
is
so a
s
ymmetric ma
trix.
T
T
T
T T
T T
T
T
proof : From (
AB) = B A
ha
we
ve (
AA ) = (A ) A = AA
0 0 0
F = 0
0
0
a
is
zer
o ma
trix of
orde
3
r × 3
0 0 0
0
G = [
0
0
0] a
is
zer
o row
vect
an
or
d H = 0
a
is
zer
o c
olumn ve t
c or
0
3
K = 3i − 2j + 4k can w
be
ritten i
ma
n
trix
as
form
- 2
4
2
L = 2i + j − k can w
be
ritten i
ma
n
trix
as
form
1
-
1
2
T
K • L = K L = [3 − 2 4] 1 = 3 ⋅ 2 + ( 2
− ) ⋅1+ (
4 − )
1 = 0
−1
in this
v
case
ector K an
v
d ector L ar
e ort
hogona (pe
l
rpendi ul
c ar.)
1 0 −
1
1
1
1
2
4
4
1
1
3
M = 2
1
1 ,
N =
−
−
,
2
4
4
0 1 −
1
− 1 1
1
2 4
4
1 0 −
1 1
1
1
1 0 0
2
4
4
1
1
3
ha
we
ve MN = 2
1
1
−
−
=
0
1
0
2
4
4
0 1 −
1 − 1
1
1
0 0 1
2 4
4
can
We
say
that M =
1
-
N an
d N =
1
-
M si
n
ce MN = .
I
If ma
trix di
is
agonal t
, he i
nverse
is
just the ma
trix w h
it
reciprocal of
di
agonal el
ements an
d
al
is
so di
agonal.
1 0 0
1 0 0
−1
1
F
ex
or ampl
e, O = 0
2
0 then O
=
0
0
2
0 0 3
1
0
0
3
cosθ
sinθ
P =
− sinθ cosθ
an
is
ort
hogonal ma
trix si
nce
cosθ − sinθ
P 1
-
= PT =
sinθ
cosθ
can
we
,
t
see hat
cosθ
sinθ cosθ
− sinθ
PPT =
− sinθ cosθ sinθ
cosθ
cos2 θ + sin2 θ
− cosθ sinθ + sinθ cosθ
=
− sinθ cosθ + cosθ sinθ
c cos2 θ + sin2 θ
1
0
=
a
for
a
ny ngleθ
0 1
Determinant
• Given square matrix, determinant of a
matrix A written |A| is defined by recursive equation as
n
i+
det(A) = A = ∑(− j
)
1
a ⋅ Minor( a )
i, j
i, j
j =1
n
=
∑
j +
(−
l
)
1
a
⋅ Minor( a )
j , l
j , l
j =1
– Starting from [a1x1] = a, and det(a)=a
• Given matrix A of order nxn
– Sign matrix of A is the matrix in the form
B=[bij]=[(-1)(i+j)]
a a a n
n
11
12
1
(− )
1 2
(− )
1 3
(−
+
)
1
1
3
4
n + 2
a
a
a n
21
22
2
(− )
1
(− )
1
(− )
1
A =
s
, ign A =
a
a
a
n +1
n + 2
2 n
n
n
nn
1
2
(− )
1
(− )
1
(− )
1
1
−1 1
−1 1
−1
= 1 −1 1
1
• Is the determinant of matrix A after taken out row ith and jth column.
a
a
a
a
a
1
2
− 3
4
5
11
12
13
14
15
a
a
a
a
a
− 2
3
4
− 5
6
21
22
23
24
25
A = a
a
a
a
a = 3
− 4
5
6
− 7
31
32
33
34
35
a
a
a
a
a
4
5
− 6
7
8
41
42
43
44
45
a
a
a
a
a
− 5
6
7
8
− 9
51
52
53
54
55
a
a
a
a
1
2
4
5
11
12
14
15
a
a
a
a
3
− 4 6 − 7
Minor( a )
31
32
34
35
=
=
23
a
a
a
a
4
5
7
8
41
42
44
45
a
a
a
a
− 5
6
8
− 9
51
52
54
55
• Cofactor aij is the minor aij with the sign according to sign pattern
• Matrix of cofactor of A is the matrix B
which each element bij is the cofactor
aij
5 6
4
6
4
5
−
1 2 3
8 9
7
9
7
8
2 3
1
3
1
2
.
Ex A = 4
5
6 , Co(A) =
−
−
7 8 9
8 9
7
9
7
8
2 3
1
3
1
2
−
5 6
4
6
4
5
Determinant of 2x2 and 3x3
Calculation of Determinant using Recursive Expansion
n
det(A) = A = ∑
i+
(−
j
)
1
a ⋅ Minor( a )
i, j
i, j
j =1
n
=
∑
j +
(−
l
)
1
a
⋅ Minor( a )
j , l
j , l
j =1
a
b
a = a,
= ad − bc
c
d
a
b
c
e
f
d
f
d
e
d
e
f = a
− b
+ c
j
k
i
k
i
j
i
j
k
= a( ek − jf ) − b( dk − if ) + c( dj − ie)
= aek-afi − bdk + bfi + cdj − cei, first row expand d
f
a
c
a
c
= b
−
+ e
− j
i
k
i
k
d
f
= b
− ( dk − if ) + e( ak − ic) − j( af − dc)
= bdk
−
+ bfi + aek − cei − afj + cdj, second column expand
Calculation of Determinant using Recursive Expansion
n
det(A) = A = ∑
i+
(−
j
)
1
a ⋅ Minor( a )
i, j
i, j
j =1
Complexity = O(n!)
n
=
∑
j +
(−
l
)
1
a
⋅ Minor( a )
j , l
j , l
j =1
a
a
a
a
11
12
13
14
a
a
a
a
21
22
23
24
a
a
a
a
31
32
33
34
a
a
a
a
41
42
43
44
a
a
a
a
a
a
a
a
a
a
a
a
22
23
24
21
23
24
21
22
24
21
22
23
= a a
a
a
− a a
a
a
+ a a
a
a
− a a
a
a
11
32
33
34
12
31
33
34
13
31
32
34
14
31
32
33
a
a
a
a
a
a
a
a
a
a
a
a
42
43
44
41
43
44
41
42
44
41
42
43
ความหมายของ Determinant
• เป็นค่า Scalar ที่สําคัญที่สุดที่บ่งบอก
คุณสมบัติของ Square Matrix
คุณสมบัติของ Determinant
คุณสมบัติของ Determinant
(Algorithm)
n
det(A) = A = ∑
i+
(−
j
)
1
a ⋅ Minor( a )
i, j
i, j
Complexity = O(n!)
j =1
n
=
∑
j +
(−
l
)
1
a
⋅ Minor( a )
j , l
j , l
j =1
a
a
a
a
11
12
13
14
ถ ้าเราบวกลบ Column เพ่ือให ้ Element ในแถว(หรือคอลัมน์) a
a
a
a
21
22
23
24
ที่ต ้องการขยายเป็นศูนย์หมดยกเว ้น Element เดียว
a
a
a
a
เราจะลงเอยด ้วยการคํานวณหา Determinant ของ Matrix 31
32
33
34
ที่มีขนาดลดลงหนึ่ง
a
a
a
a
41
42
43
44
a
a
a
a
a
a
a
a
a
a
a
a
22
23
24
21
23
24
21
22
24
21
22
23
= a a
a
a
− a a
a
a
+ a a
a
a
− a a
a
a
11
32
33
34
12
31
33
34
13
31
32
34
14
31
32
33
a
a
a
a
a
a
a
a
a
a
a
a
42
43
44
41
43
44
41
42
44
41
42
43
การบวกลบดังกล่าวต ้องมีหลักการ มิฉะนั้นผลลัพธ์จะไม่ถูกต ้อง
เราจะใช ้คุณสมบัติข ้อ 9 และ 10 ของ Determinant เพื่อกระทําดังกล่าว
Algorithm การหา Determinant ที่
มีประสิทธิภาพ
• ใช ้คุณสมบัติข ้อ 10 ร่วมกับข ้อ 9 เพื่อสร ้างเป็น Algorithm
– 1. มองหา Element ใน Matrix ที่มีค่าเท่ากับ 1 ถ ้าหาไม่ได ้ เลือก
Element ใดก็ได ้ จากนั้นหารทั้งแถว หรือหารทั้ง Column ด ้วยค่า
ของ Element นั้นเพื่อทําให ้ค่าเป็น 1 ตัวเลขที่มาหารนั้นจะต ้อง
กลับนํามาคูณกับคําตอบที่ได ้ เป็นค่า Determinant ที่ต ้องการ
(คุณสมบัติข ้อ 9)
– 2. พิจารณาว่าจะ Expand แบบแถวหรือ Column ผ่าน Element ที่
เลือก จากนั้นกําจัด Element อื่นในแนวที่ Expand เป็นศูนย์ให ้
หมด(คุณสมบัติข ้อ 10) สมมุติเราเลือก Element a(x,y)
• ถ ้าจะ Expand แบบแถว ให ้บวกลบ Column อื่นกับ Column ที่
ผ่าน Element ที่เลือก เพื่อให ้ Element ในแถวที่จะ Expand เป็นศูนย์ทั้งหมด ยกเว ้น Element ที่เลือก
– Col(j) ใหม่ = Col(j) เก่า – a(x,j)*Col(y); j = 1,2,..,n ยกเว ้น y
• ถ ้าจะ Expand แบบ Column ให ้บวกลบแถวอื่นกับแถวที่ผ่าน
Element ที่เลือก เพื่อให ้ Element ใน Column ที่จะ Expand เป็นศูนย์ทั้งหมด ยกเว ้น Element ที่เลือก
– Row(i) ใหม่ = Row(i) เก่า – a(i,y)*Row(x); i = 1,2,..,n ยกเว ้น x
Algorithm การหา Determinant ที่
มีประสิทธิภาพ(ต่อ)
– 3.ทําการ Expand ตามสูตร เราจะลงเอยด ้วย
การหา Determinant ของ Matrix ที่มีขนาด
ลดลงหนึ่งเพียงครั้งเดียว
– 4. วิธีนี้สามารถทําเป็น Recursive เพื่อลดการ
หา Determinant ของ Matrix ขนาดใหญ่
เหลือแค่การหา Determinant ของ Matrix 2x2
หรือ 3x3
การหา Determinant
การหา Determinant
Inverse of Matrix
Inverse of Matrix
Inverse of Matrix
Inverse of Matrix
Inverse of Matrix
• การคํานวณตามสมการที่กล่าวมา จะใช ้การ
คํานวณมากเกินไป
• หลัง Midterm เราจะมาดู Algorithm ที่มี
ประสิทธิภาพ เพื่อใช ้ในการหา Matrix
Inverse
– Gauss-Jordan Method
Matrix Norms
Norms
เรียก Spectral Radius ของ X
• Download HW 1 Question Sheet จาก
Website
– พิมพ์ Question Sheet ลงบนกระดาษ A4
– ทําการบ ้าน โดยแสดงวิธีทําและคําตอบในช่อง
ที่กําหนด ด ้วยลายมือนักศึกษา ห ้ามพิมพ์ ต ้อง
ใช ้กระดาษที่พิมพ์นี้ทําการบ ้าน
– เขียนชื่อที่หัวกระดาษ ส่งอาทิตย์หน ้าต ้นชั่วโมง
– ไม่รับงานที่ไม่เป็นไปตามที่กําหนด